package edu.online.dal;

import edu.online.entity.StudentEntity;
import org.apache.ibatis.jdbc.SQL;

public class StudentEntitySqlProvider {

    public String insertSelective(StudentEntity record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("student");
        
        if (record.getUserid() != null) {
            sql.VALUES("UserId", "#{userid,jdbcType=CHAR}");
        }
        
        if (record.getUsername() != null) {
            sql.VALUES("UserName", "#{username,jdbcType=VARCHAR}");
        }
        
        if (record.getPasswd() != null) {
            sql.VALUES("Passwd", "#{passwd,jdbcType=VARCHAR}");
        }
        
        if (record.getEmail() != null) {
            sql.VALUES("Email", "#{email,jdbcType=VARCHAR}");
        }
        
        if (record.getMobile() != null) {
            sql.VALUES("Mobile", "#{mobile,jdbcType=CHAR}");
        }
        
        if (record.getRole() != null) {
            sql.VALUES("Role", "#{role,jdbcType=VARCHAR}");
        }
        
        if (record.getStudentname() != null) {
            sql.VALUES("StudentName", "#{studentname,jdbcType=VARCHAR}");
        }
        
        if (record.getSsex() != null) {
            sql.VALUES("SSex", "#{ssex,jdbcType=CHAR}");
        }
        
        if (record.getQq() != null) {
            sql.VALUES("QQ", "#{qq,jdbcType=VARCHAR}");
        }
        
        if (record.getRequirement() != null) {
            sql.VALUES("Requirement", "#{requirement,jdbcType=VARCHAR}");
        }
        
        if (record.getDiscountrate() != null) {
            sql.VALUES("DiscountRate", "#{discountrate,jdbcType=DECIMAL}");
        }
        
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(StudentEntity record) {
        SQL sql = new SQL();
        sql.UPDATE("student");
        
        if (record.getUsername() != null) {
            sql.SET("UserName = #{username,jdbcType=VARCHAR}");
        }
        
        if (record.getPasswd() != null) {
            sql.SET("Passwd = #{passwd,jdbcType=VARCHAR}");
        }
        
        if (record.getEmail() != null) {
            sql.SET("Email = #{email,jdbcType=VARCHAR}");
        }
        
        if (record.getMobile() != null) {
            sql.SET("Mobile = #{mobile,jdbcType=CHAR}");
        }
        
        if (record.getRole() != null) {
            sql.SET("Role = #{role,jdbcType=VARCHAR}");
        }
        
        if (record.getStudentname() != null) {
            sql.SET("StudentName = #{studentname,jdbcType=VARCHAR}");
        }
        
        if (record.getSsex() != null) {
            sql.SET("SSex = #{ssex,jdbcType=CHAR}");
        }
        
        if (record.getQq() != null) {
            sql.SET("QQ = #{qq,jdbcType=VARCHAR}");
        }
        
        if (record.getRequirement() != null) {
            sql.SET("Requirement = #{requirement,jdbcType=VARCHAR}");
        }
        
        if (record.getDiscountrate() != null) {
            sql.SET("DiscountRate = #{discountrate,jdbcType=DECIMAL}");
        }
        
        sql.WHERE("UserId = #{userid,jdbcType=CHAR}");
        
        return sql.toString();
    }
}